﻿using Lamex.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mNC.Common
{
    public class CheckQRCode
    {
        public static bool CheckIsExistDB(string Username)
        {
            bool flag = false;
            string sql = @"SELECT BARCODE_NO,MACHINE_NO
FROM [LamexMESManager].[dbo].[NC_PN_AL_Manufacture_Process_Record]
WHERE MACHINE_NO='" + Username.Trim() + "' AND ISNULL(FLAG,'')=0";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            if (dt.Rows.Count > 0)
                flag = true;
            return flag;
        }

        public static bool CheckIsOverTime(string Username)
        {
            bool flag = false;
            string sql = @"SELECT TOP 1 SCAN_TIME
FROM [LamexMESManager].[dbo].[NC_PN_AL_Manufacture_Process_Record]
WHERE MACHINE_NO='" + Username.Trim() + "' AND ISNULL(FLAG,'')=1 ORDER BY SCAN_TIME DESC";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            if (dt.Rows.Count > 0 && dt != null)
            {
                DateTime startTime = Convert.ToDateTime(dt.Rows[0]["SCAN_TIME"]);
                DateTime endTime = DateTime.Now;
                TimeSpan span = endTime.Subtract(startTime);
                decimal Seconds = Convert.ToDecimal(span.TotalSeconds);
                if (Seconds <= 30)
                    flag = true;
            }
            return flag;
        }
    }
}
